<?php
include 'secure/core.php';
if(isset($_POST['submit'])){
      if (!isset($_POST['agreement'])) {
		header( 'Location: login.php?msg=5' ) ;	
		exit;
	}
        $ret_val = $users->is_loginValid(mysql_real_escape_string($_POST['user_name']),mysql_real_escape_string($_POST['password']));
	if($ret_val == -1){		
		header( 'Location: login.php?msg=1' ) ;	
		exit();
	}
	else{				
		$_SESSION['userid'] = $ret_val['id'];
		$_SESSION['username'] = $ret_val['username'];
		$_SESSION['pass'] = md5($_POST['password']);
		$_SESSION['email'] = $users->getEmailAddress();
		$_SESSION['status'] = $users->getUserStatus();			
		header( 'Location: dashboard.php?msg=1' ) ;	
		exit();	
	}		
}
include 'header.php';
include 'left.php'; 	
?>
		<div id="right">

			<div class="section">
			<?php if($_GET['msg'] == '1') { ?>
			 <div class="message red"><span><b>Error</b>: The email or password is incorrect.</span></div>
			 <?php } ?>	
			 <?php if($_GET['msg'] == '2') { ?>
			 <div class="message green"><span><b>Success</b>: Account Created, Check your emails for further instructions.</span></div>
			 <?php } ?>
			 <?php if($_GET['msg'] == '3') { ?>
			 <div class="message green"><span><b>Success</b>: Your Account has been verified. Please login</span></div>
			 <?php } ?>
			 <?php if($_GET['msg'] == '4') { ?>
			 <div class="message blue"><span><b>Information</b>: Your account has been suspended. Contact support immediately.</span></div>
			 <?php } ?>
			 <?php if($_GET['msg'] == '5') { ?>
			 <div class="message blue"><span><b>Error</b>: You must agree to using the site within the Terms of Service.</span></div>
			 <?php } ?>
			 
							<div class="box">

					<div class="title">

						Login

					</div>

					<div class="content">

						<form action="login.php" method="post">

							<div class="row">

								<label>Username</label>

								<div class="right"><input type="text" value="" name="user_name" class="{validate:{required:true, messages:{required:'Please enter your email'}}}" /></div>

							</div>

							<div class="row">

								<label>Password</label>

								<div class="right"><input type="password" value="" name="password" class="{validate:{required:true, messages:{required:'Please enter your password'}}}" /></div>

							</div>
							
							<div class="row">

								<label>Agreement</label>

								<div class="right">

									<input type="checkbox" name="agreement" id="agreement"/>

									<label for="agreement">I will be using the site according to the <a href="tos.php" >Terms of Service</a></label>

								</div>

							</div>

							<div class="row">

								<div class="right">

									<button type="submit" name="submit" class="green"><span>Login</span></button>

								</div>

							</div>

						</form>

					</div>

				</div>

			</div>

		</div>

</div>
<?php include 'footer.php'; ?>